﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Interactivity;

namespace ExtendedControls
{
    public class MenuCommandCollection : TriggerAction<Button>
    {
        public MenuCommandCollection():base(){}        
        public readonly DependencyProperty ItemsProperty = DependencyProperty.Register("Items", typeof(List<ICommand>), typeof(MenuCommandCollection),new PropertyMetadata(new List<ICommand>()));
        public List<ICommand> Items
        {
            get
            {                                               
                return (List<ICommand>)this.GetValue(ItemsProperty);
            }
            set
            {                
                this.SetValue(ItemsProperty, value);                
            }
        }
        protected override void OnAttached()
        {
            base.OnAttached();            
        }

        protected override void OnDetaching()
        {
            base.OnDetaching();
        }
        protected override void Invoke(object parameter)
        {
            if (Items != null)
                foreach (ICommand cmd in Items)
                {
                    cmd.Do(AssociatedObject);
                }
        }
    }
}